package cn.gzsxt.music.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gzsxt.music.mapper.PowerMapper;
import cn.gzsxt.music.query.PowerQueryObject;
import cn.gzsxt.music.service.PowerService;

@Service
public class PowerServiceImpl implements PowerService {
	
	@Autowired
	private PowerMapper mapper;

	@Override
	public Map<String, Object> selectPowerDataByCondition(PowerQueryObject qo) {
		
		Map<String,Object> datagirdMap = new HashMap<>();
		//查询总数
		datagirdMap.put("total", mapper.selectPowerTotalByCondition(qo));
		//查询结果集
		datagirdMap.put("rows", mapper.selectPowerListByCondition(qo));
		
		return datagirdMap;
	}

	@Override
	public int savePower(Map<String, Object> params) {
		try {
			Map<String, Object> power = mapper.checkExistsPwerAction(params);
			if(power == null) {
				return mapper.insert(params);
			}else {
				//自定返回标识,判断是否有:有返回2
				return 2;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int deletePowerById(Long power_id) {
		return mapper.deletePowerById(power_id);
	}

	@Override
	public int updatePower(Map<String, Object> params) {
		try {
			Map<String, Object> power = mapper.checkExistsPwerAction(params);
			if(power == null) {
				return mapper.update(params);
			}else {
				//自定返回标识,判断是否有:有返回2
				return 2;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public Map<String, Object> getPowerByPowerActions(String role_action) {
		Map<String,Object> datagirdMap = new HashMap<>();
		//查询总数
		datagirdMap.put("rows",mapper.getPowerByPowerActions(role_action));
		return datagirdMap;
	}

	@Override
	public List<Map<String, Object>> getAllPowers() {
		return mapper.getAllPowers();
	}


}
